QuickStart
Contents
QuickStart
Start once detection within 5 lines of code.
from streamad.util import StreamGenerator, UnivariateDS
from streamad.model import SpotDetector
ds = UnivariateDS()
stream = StreamGenerator(ds.data)
detector = SpotDetector()
for x in stream.iter_item():
score = detector.fit_score(x)
# print("\r Anomaly score: {}".format(score), end="", flush="True")
Univariate time series
Detection, evaluation and visualization. Note that the gray line is the ground truth of anomalies.
from streamad.util import StreamGenerator, UnivariateDS, AUCMetric, plot
from streamad.model import SpotDetector
ds = UnivariateDS()
stream = StreamGenerator(ds.data)
model = SpotDetector()
scores = []
for x in stream.iter_item():
score = model.fit_score(x)
scores.append(score)
# print("\r Anomaly score: {}".format(score), end="", flush="True")
data, label, date, features = ds.data, ds.label, ds.date, ds.features
auc_score = AUCMetric().evaluate(label, scores)
plot(data,label,date,scores,features)
Multivariate time series
An example of multivariate time series detection.
from streamad.util import StreamGenerator, MultivariateDS, AUCMetric, plot
from streamad.model import xStreamDetector
ds = MultivariateDS()
stream = StreamGenerator(ds.data)
model = xStreamDetector()
scores = []
for x in stream.iter_item():
score = model.fit_score(x)
scores.append(score)
# print("\r Anomaly score: {}".format(score), end="", flush="True")
data, label, date, features = ds.data, ds.label, ds.date, ds.features
auc_score = AUCMetric().evaluate(label, scores)
plot(data,label,date,scores,features)